import numpy as np

a = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9])

print(a)

print('%s %s' % ('取数组前3个的值', a[:3]))

print('%s %s' % ('取数组的后３个的值', a[-3:]))

print('%s %s' % ('取数组后３个以前的值', a[:-3]))

# 生成5*5对角阵
b = np.eye(5)

print(b)

print('%s %s' % ('取二维数组前3列的值\n', b[:, :3]))

print('%s %s' % ('取二维数组前三行前三列的值\n', b[:3, :3]))

print('%s %s' % ('取二维数组最后一列之前的值\n', b[:, :-1]))

print('%s %s' % ('取二维数组第二列到最后一列之前的值\n', b[:, 1:-1]))

print('%s %s' % ('取二维数组最后一列的值\n', b[:, -1]))













